@{	
	var appcfg=@Model.dcCfgs.appConfigs;
	var funcName =@Model.codeTools.humpNaming(2,Model.tabname);
	var className =@Model.codeTools.humpNaming(1,Model.tabname);
}<template>
  <div class="page-panel">
    <div class="header-bar">
      <el-button
        v-if="!addPower"
        icon="el-icon-plus"
        size="mini"
        type="primary"
        @("@")click="handleAdd"
      >添加</el-button>
    </div>
    <el-table height="100%" v-loading="loading" :data="dataList" stripe row-key="id" ref="table">
        @foreach(var col in Model.tabinfo){
            var colName = Model.codeTools.humpNaming(1,col.columnName);
            <el-table-column prop="@colName" label="@col.columnName"></el-table-column>
        }
      <el-table-column label="操作" width="280">
        <template slot="header"></template>
        <template slot-scope="scope">
          <el-button
            v-if="!editPower"
            icon="el-icon-edit"
            size="mini"
            @("@")click="handleEdit(scope.$index, scope.row)"
          >编辑</el-button>
          <el-button
            icon="el-icon-refresh-left"
            size="mini"
            type="success"
            @("@")click="handleDel(scope.$index, scope.row,1)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="footer-bar">
      <el-row :gutter="20" type="flex" align="middle" class="pagination">
        <el-col :span="24">
          <el-pagination
            background
            text-right
            @("@")current-change="currentChange"
            :current-page="pageInfo.currentPage"
            :page-size="pageInfo.pageSize"
            layout="total, prev, pager, next"
            :total="pageInfo.total"
          ></el-pagination>
        </el-col>
      </el-row>
    </div>
    <el-dialog
      :title="'场地信息 : '+value.Id||'添加'"
      :visible.sync="dialogFormVisible"
      @("@")open="dialogOpened"
    >
      <form-generator :value="value" @("@")change="onFormCtrlChange" ref="form" :settings="formSettings"></form-generator>
      <div slot="footer" class="dialog-footer">
        <el-button @("@")click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @("@")click="onInfoSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { @(className)Form, @(className)Info } from "./@(Model.tabname)_form";
import { mapActions, mapState } from "vuex";
import { PageInfo } from "@("@")/modules/common";
import moment from "moment";

export default {
  name: "@(Model.tabname)-list",
  data() {
    return {
      dialogFormVisible: false,
      formSettings: Object.assign({}, @(className)Form),
      value: new @(className)Info(),
      powers: [],
      dataList: [],
      pageInfo: new PageInfo()
    };
  },
  created() {},
  mounted() {
    this.dataLoad(this.pageInfo);
    this.getMyPowers().then(x => {
      this.powers = x || [];
    });
  },
  computed: {
    ...mapState("company_user", ["loading"]),
    addPower() {
      const power_key = "/companyUser/add";
      return this.powers.find(x => x.rescode == power_key) != undefined;
    },
    editPower() {
      const power_key = "/companyUser/update";
      return this.powers.find(x => x.rescode == power_key) != undefined;
    },
    delPower() {
      const power_key = "/companyUser/del";
      return this.powers.find(x => x.rescode == power_key) != undefined;
    }
  },
  methods: {
    ...mapActions("global", ["getMyPowers"]),
    ...mapActions("@Model.tabname", [
      "getList",
      "add",
      "update",
      "del",
      "getById"
    ]),
    dataLoad(pinfo) {
      this.getList(pinfo).then(result => {
        if (result.code != 0) {
          return;
        }
        this.$set(this.pageInfo, "total", result.data.total);
        this.dataList = result.data.list || [];
      });
    },

    currentChange(ev) {
      let pageInfo = this.pageInfo;
      pageInfo.currentPage = ev;
      this.getList(pageInfo);
    },
    handleEdit(index, row) {
      this.getById(row.Id).then(x => {
        if (x.code != 0) {
          this.$notify.error({
            title: "错误",
            message: x.msg
          });
          return;
        }
        let info = Object.assign({}, new @(className)Info(), x.data);
        this.value = info;
        this.dialogFormVisible = true;
      });
    },

    handleDel(index, row) {
      this.$confirm(`是否要删除(${row.Id})?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.del().then(result => {
            if (result.code == 0) {
              this.$message({
                type: "success",
                message: `删除成功!`
              });
              this.dataLoad(this.pageInfo);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: `已取消删除`
          });
        });
    },
    handleAdd() {
      this.value = new @(className)Info();
      this.dialogFormVisible = true;
    },
    dialogOpened() {
      let form = this.$refs["form"];
      if (!form) {
        setTimeout(() => {
          this.dialogOpened();
        }, 100);
        return;
      }
      form.resetForm();
      this.value.BusinessHours = [
        moment(this.value.StartTime),
        moment(this.value.EndTime)
      ];
      form.setValues(Object.assign({}, this.value));
    },

    onInfoSubmit() {
      let vals = this.$refs["form"].formSubmit();
      if (!vals) {
        return;
      }

      vals.StartTime = moment(vals.BusinessHours[0]).format(
        "YYYY-MM-DDTHH:mm:ssZ"
      );
      vals.EndTime = moment(vals.BusinessHours[1]).format(
        "YYYY-MM-DDTHH:mm:ssZ"
      );
      delete vals.BusinessHours;
      if (vals.Id == 0) {
        this.add(vals).then(result => {
          if (result.code == 0) {
            this.dataLoad(this.pageInfo);
            this.dialogFormVisible = false;
          } else {
            this.$notify.error({
              title: "错误",
              message: result.msg
            });
          }
        });
      } else {
        this.update(vals).then(result => {
          if (result.code == 0) {
            this.dataLoad(this.pageInfo);
            this.dialogFormVisible = false;
          } else {
            this.$notify.error({
              title: "错误",
              message: result.msg
            });
          }
        });
      }
    },

    //表单项改动事件
    onFormCtrlChange(ev) {}
  }
};
</script>

<style lang="scss">
</style>
